#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
Created on 2014年9月5日

@author: monstar-216
'''

# import token

# from datetime import datetime, date,time,timedelta
# from random import random, randint
# import time as ts

def get_user_walking_distance(login_count):
    today_pt = 0
    total_pt = 0
    if login_count <= 7:
        today_pt = 5 * login_count
        for i in range(1,login_count+1):
            total_pt += 5 * i
    else:
        today_pt = 5 * 7 + (login_count - 7)
        for i in range(1,8):
            print i
            total_pt += 5 * i
            
        for i in range(8,login_count+1):
            print i
            total_pt += 35 + (i - 7)
            
    return {
            'today_pt':today_pt,
            'total_pt':total_pt
            }
def get_team_walking_max(team_lv, day_count):
    base = team_lv * 10
    
    return base * get_user_walking_distance(day_count)['total_pt']


def calcu_ranking_begin_time(now_time, nat_begin_time,yesterday=False): 
    res = {}
    if now_time.time <= nat_begin_time.time:
        #超过开始time
        t = now_time.replace(hour=nat_begin_time.hour,minute=nat_begin_time.minute,second=nat_begin_time.second)
        t1 = t + timedelta(days=1)
        res['pref'] = t
        res['next'] = t1
    else:
        t1 = now_time.replace(hour=nat_begin_time.hour,minute=nat_begin_time.minute,second=nat_begin_time.second)
        t = t1 + timedelta(days=-1)
        res['pref'] = t
        res['next'] = t1
    if yesterday:
        res['pref'] += timedelta(days=-1)
        res['next'] += timedelta(days=-1)
    return res
'''
if __name__ == '__main__':
    lv_list = ({'lv': 3L, 'count': 0L}, {'lv': 4L, 'count': 0L},{'lv': 5L, 'count': 36L}, {'lv': 6L, 'count': 2L}, {'lv': 8L, 'count': 1L}, {'lv': 9L, 'count': 2L}, {'lv': 10L, 'count': 1L})
    user_lv = 6
    lv_gap = 10
    min_lv = lv_list[0]['lv']
    max_lv = lv_list[-1]['lv']
    ride_rounds = 3
    R = ride_rounds // 3 #limit 
    T = ride_rounds % 3 #+lv
    low_lv = user_lv - lv_gap
    up_lv = user_lv + lv_gap
    if user_lv - min_lv <= lv_gap:
        low_lv = min_lv
    if max_lv - user_lv <= lv_gap:
        up_lv = max_lv
    
    l_len = len(lv_list)
    lv_list_2 = []
    t = 0
    for i in range(0,max_lv+1):
        if lv_list[t]['lv'] != i:
            lv_list_2.append({"lv":i,"count":0})
        else:
            lv_list_2.append(lv_list[t])
            t += 1
    print lv_list_2
    print 'ride_rounds,R,T:',ride_rounds,R,T
    
    
    if lv_list_2[low_lv+T]['count'] <= R:
        print lv_list_2[low_lv+T]
        low_lv = user_lv - 1
        if lv_list_2[low_lv]['count'] <= R:
            #随机
            R = randint(1, sum([lv_list_2[user_lv]['count'],lv_list_2[user_lv-1]['count'],lv_list_2[user_lv+1]['count']]))
            print R 
        else:
            print lv_list_2[low_lv]
    else:
        print lv_list_2[low_lv+T]
    
    R = randint(1, sum([lv_list_2[user_lv]['count'],lv_list_2[user_lv-1]['count'],lv_list_2[user_lv+1]['count']]))
    print R 
    
    print '--------------'
    R = ride_rounds // 3 #limit 
    T = ride_rounds % 3 #+lv
    print 'ride_rounds,R,T:',ride_rounds,R,T
    print lv_list_2[low_lv+R]
    '''


def get_rank_date(now_time, nat_begin_time,date_type=1): 
    #1：today 2：yesterday
    res = {}
    rank_date = None
    n_hour = now_time.hour
    b_hour = nat_begin_time.hour
    if int(n_hour) <= int(b_hour):
        rank_date = now_time + timedelta(days=-1)
    else:
        rank_date = now_time
    
    return rank_date


data = [{
                "category_id": 0,
                "sub_category": 1,
                "name": "インナー"
            }, {
                "category_id": 0,
                "sub_category": 2,
                "name": "ボトムス"
            }, {
                "category_id": 0,
                "sub_category": 3,
                "name": "アウター"
            }, {
                "category_id": 0,
                "sub_category": 4,
                "name": "セットアップ"
            }, {
                "category_id": 1,
                "sub_category": 5,
                "name": "靴"
            }, {
                "category_id": 2,
                "sub_category": 0,
                "name": "背景"
            }, {
                "category_id": 2,
                "sub_category": 7,
                "name": "メガネ・グラサン"
            }, {
                "category_id": 2,
                "sub_category": 8,
                "name": "マスク"
            }, {
                "category_id": 3,
                "sub_category": 6,
                "name": "キャップ系"
            }, {
                "category_id": 3,
                "sub_category": 9,
                "name": "ブレス系"
            }, {
                "category_id": 3,
                "sub_category": 10,
                "name": "ネックレス系"
            }, {
                "category_id": 4,
                "sub_category": 14,
                "name": "肌色"
            }, {
                "category_id": 5,
                "sub_category": 15,
                "name": "顔面整形"
            }, {
                "category_id": 6,
                "sub_category": 16,
                "name": "髪型"
            }, {
                "category_id": 7,
                "sub_category": 12,
                "name": "武器（左）"
            }, {
                "category_id": 7,
                "sub_category": 13,
                "name": "武器（右）"
            }, {
                "category_id": 9,
                "sub_category": 2,
                "name": "タイヤ&ホイール"
            }, {
                "category_id": 9,
                "sub_category": 3,
                "name": "フロントフォーク"
            }, {
                "category_id": 9,
                "sub_category": 4,
                "name": "フロントカウル"
            }, {
                "category_id": 9,
                "sub_category": 5,
                "name": "フロントフェンダー"
            }, {
                "category_id": 9,
                "sub_category": 6,
                "name": "アンダーカウル"
            }, {
                "category_id": 9,
                "sub_category": 7,
                "name": "ハンドル"
            }, {
                "category_id": 9,
                "sub_category": 8,
                "name": "タンク"
            }, {
                "category_id": 9,
                "sub_category": 9,
                "name": "シート"
            }, {
                "category_id": 9,
                "sub_category": 10,
                "name": "エンジン"
            }, {
                "category_id": 9,
                "sub_category": 11,
                "name": "サイドカバー"
            }, {
                "category_id": 9,
                "sub_category": 12,
                "name": "サス"
            }, {
                "category_id": 9,
                "sub_category": 13,
                "name": "マフラー"
            }, {
                "category_id": 9,
                "sub_category": 14,
                "name": "リアボディ"
            }, {
                "category_id": 9,
                "sub_category": 15,
                "name": "リアフット"
            }, {
                "category_id": 9,
                "sub_category": 16,
                "name": "ステップ"
            }, {
                "category_id": 9,
                "sub_category": 17,
                "name": "オプションパーツ1"
            }, {
                "category_id": 9,
                "sub_category": 18,
                "name": "オプションパーツ2"
            }, {
                "category_id": 9,
                "sub_category": 19,
                "name": "オプションパーツ3"
            }, {
                "category_id": 9,
                "sub_category": 20,
                "name": "オプションパーツ4"
            }, {
                "category_id": 9,
                "sub_category": 21,
                "name": "旗"
            }, {
                "category_id": 9,
                "sub_category": 22,
                "name": "エンジンカバー"
            }]

if __name__ == '__main__':
    s = '2014-11-18 00:00:00'
    import time
    t = time.strftime('2014-11-18 00:00:00')
    print type(t)
    
    
    
    